package com.cskaoyan.market.service;

import com.cskaoyan.market.db.domain.MarketAddress;
import com.cskaoyan.market.db.domain.MarketAddressExample;
import com.cskaoyan.market.db.mapper.MarketAddressMapper;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: YaLiFeng
 * @description: TODO
 * @date: 2024/5/6 17:27
 */
@Service
public class MarketAddressServiceImpl implements MarketAddressService {
    @Autowired
    MarketAddressMapper marketAddressMapper;
    @Override
    public List<MarketAddress> list(Integer limit, Integer page, String sort, String order,String name,String userId) {
        MarketAddressExample marketAddressExample=new MarketAddressExample();
        marketAddressExample.setOrderByClause(sort+" "+order);
        MarketAddressExample.Criteria criteria=marketAddressExample.createCriteria();
        if(!StringUtils.isEmpty(name)){
            criteria.andNameLike("%"+name+"%");
        }
        if(!StringUtils.isEmpty(userId)){
            criteria.andUserIdEqualTo(Integer.valueOf(userId));
        }
        PageHelper.startPage(page,limit);
        List<MarketAddress> marketAddresses=marketAddressMapper.selectByExampleSelective(marketAddressExample,MarketAddress.Column.id,MarketAddress.Column.userId,MarketAddress.Column.name,
        MarketAddress.Column.areaCode, MarketAddress.Column.addressDetail);
//        List<MarketAddress> marketAddresses=marketAddressMapper.selectByExample(marketAddressExample);
        return marketAddresses;
    }
}
